package jp.sourceforge.akjrcp.util;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SelectionUtils {
public static File[] getSelectFiles(ISelection selection){
	List<File> files=new ArrayList<File>();
	if(selection instanceof StructuredSelection){
		StructuredSelection s=(StructuredSelection)selection;
		Object[] items=s.toArray();
		for (int i = 0; i < items.length; i++) {
			if(items[i] instanceof File){
				files.add((File) items[i]);
			}
		}
	}
	return files.toArray(new File[files.size()]);
	}

public static Object[] getSelectObject(ISelection selection){
	if(selection instanceof StructuredSelection){
		return ((StructuredSelection)selection).toArray();
	}
	return new Object[0];
	}
public static File getSelectFile(ISelection selection){
	File files[]=getSelectFiles(selection);
	if(files.length>0){
		return files[0];
	}else{
		return null;
	}
}
}
